from fastapi import FastAPI
from app.api.router import router as api_router
from app.core.redis import redis_client
from contextlib import asynccontextmanager


@asynccontextmanager
async def lifespan(app: FastAPI):
    # app startup
    await redis_client.init_redis()
    print("Redis 连接已建立")
    yield
    # app teardown
    await redis_client.close_redis()
    print("应用关闭，Redis 连接已关闭")


app = FastAPI(title="Redis 示例应用", lifespan=lifespan)


app.include_router(api_router)
